package me.zhengjie.modules.website.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.modules.security.service.dto.AuthUserDto;
import me.zhengjie.modules.website.dto.SendVerificationCodeDto;
import me.zhengjie.modules.website.dto.VerificationCodeDto;
import me.zhengjie.modules.website.service.impl.VerificationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/verification/website")
@Api(tags = " 网页-手机验证码")
public class VerificationController {

    @Autowired
    private VerificationServiceImpl verificationService;


    @ApiOperation(value = "发送验证码", notes = "通过手机号发送验证码，验证码有效期10分钟")
    @PostMapping("/sendVerificationCode")
        public ResponseEntity<?> sendVerificationCode(@RequestBody SendVerificationCodeDto dto) {
        return verificationService.sendVerificationCode(dto.getPhoneNumber());
    }

    @ApiOperation(value = "验证验证码", notes = "根据手机号和验证码验证，验证码有效期10分钟")
    @PostMapping("/verifyVerificationCode")
    public ResponseEntity<?> verifyVerificationCode(@RequestBody VerificationCodeDto dto,
                                                    HttpServletRequest request) {
        return verificationService.verifyVerificationCode(dto.getPhoneNumber(), dto.getVerificationCode(), request);
    }
}
